//
//  MLWWWHotTableViewCell.m
//  KITCHEN_STORIES
//
//  Created by dllo on 16/6/8.
//  Copyright © 2016年 MLW. All rights reserved.
//

#import "MLWWWHotTableViewCell.h"
#import "MLWWWCollectionTableViewCell.h"


@implementation MLWWWHotTableViewCell


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self =  [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        UICollectionViewFlowLayout *flowlayout = [[UICollectionViewFlowLayout alloc]init];
        
        flowlayout.itemSize = CGSizeMake(365 / 2, 122);
        
        flowlayout.minimumLineSpacing = 0;
        
        flowlayout.minimumInteritemSpacing = 0;
        
        flowlayout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
        
        flowlayout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        
        self.hotCollectionView = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, 365, 122) collectionViewLayout:flowlayout];
        
        [flowlayout release];
        
        self.hotCollectionView.backgroundColor = [UIColor whiteColor];
        
        self.hotCollectionView.dataSource = self;
        
        self.hotCollectionView.delegate = self;
        
        self.hotCollectionView.showsHorizontalScrollIndicator = NO;
        //注册
        [self.hotCollectionView registerClass:[MLWWWCollectionTableViewCell class] forCellWithReuseIdentifier:@"mLWWWCollectionTableViewCell"];
        
        [self addSubview:_hotCollectionView];
        
        [_hotCollectionView release];
        
    }
    return self;
}














#pragma mark --- collectionView代理方法
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    MLWWWCollectionTableViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"mLWWWCollectionTableViewCell" forIndexPath:indexPath];
    
    MLWWWHotItemModel *model = [self.hotModel.list objectAtIndex:indexPath.item];
    
    
    cell.hotItemModel = model;
    
        
    return cell;
    
    
}



-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.hotModel.list.count;
}






-(void)setHotModel:(MLWWWHotModel *)hotModel
{
    if (_hotModel != hotModel) {
        [_hotModel release];
        _hotModel = [hotModel retain];
        [self.hotCollectionView reloadData];
    }
}







//- (void)awakeFromNib {
//    [super awakeFromNib];
//    // Initialization code
//}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
